//
//  YTFeedBackController.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/28.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTFeedBackController.h"

@interface YTFeedBackController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *textView; // textView
@property (weak, nonatomic) IBOutlet UIButton *feedbacButton;   // 反馈按钮
@property (weak, nonatomic) IBOutlet UILabel *placeHolder;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *feedbackBtnBottomCons;

@end

@implementation YTFeedBackController

#pragma mark: - 提交按钮 监听
- (IBAction)feedbackButtonClick
{
    if (!self.textView.hasText) {
        [self.view showTipWithTipStr:@"请输入您的意见"];
        return;
    }
    
    [YTNetworkManager.shareManager postFeedBackWithContent:self.textView.text
                                                completion:^(BOOL isSucc, NSString *statusInfo)
    {
        if (!isSucc) {
            [self.view showTipWithTipStr:statusInfo];
            return ;
        }
        
        [self.view showTipWithTipStr:statusInfo];
        [self.navigationController popViewControllerAnimated:true];
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.textView.layer.borderWidth = 1;
    self.textView.layer.borderColor = UIColor.lightGrayColor.CGColor;
    self.textView.layer.cornerRadius = 8;
    self.textView.layer.masksToBounds = YES;
    
    self.textView.delegate = self;
    
    // 注册键盘弹出通知
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardDidChange:) name:UIKeyboardDidChangeFrameNotification object:nil];
    
    [self.textView becomeFirstResponder];
    
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"icon_logo"]];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"倛袨1"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClick)];
    
    [self.navigationItem.leftBarButtonItem setTintColor:kBackButtonColor];

}

// 返回按钮
- (void)backButtonClick
{
    [self.navigationController popViewControllerAnimated:true];
}



- (void)dealloc
{
    [NSNotificationCenter.defaultCenter removeObserver:self];
}


#pragma mark； - 键盘弹出通知
- (void)keyboardDidChange:(NSNotification *)n
{
    CGRect rect = [n.userInfo[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
    
    self.feedbackBtnBottomCons.constant = 12 + rect.size.height;
    
    [UIView animateWithDuration:0.25 animations:^{
        [self.view layoutIfNeeded];
    }];
    
}



#pragma mark: - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView
{
    self.placeHolder.hidden = textView.hasText;
}

@end
